# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Gennadiy Mykhailiuta <gmykhailiuta@gmail.com>
# Contributor: Xuanwo <xuanwo@archlinuxcn.org>

pkgname=obsidian
pkgver=1.2.7
pkgrel=1
pkgdesc="A powerful knowledge base that works on top of a local folder of plain text Markdown files"
arch=('loong64' 'x86_64')
url="https://obsidian.md/"
license=('custom:Commercial')
depends=('zlib' 'hicolor-icon-theme' 'fuse' 'electron')
makedepends=('asar')
options=(!strip)
source=("obsidian.sh"
        "obsidian.desktop"
        "https://github.com/obsidianmd/obsidian-releases/releases/download/v${pkgver}/obsidian-${pkgver}.tar.gz"
)
sha256sums=('b5dcbbded25b7f65fd274eb9c98c4a4143e9c405074f97c5123c56df5482bd91'
            'be67713e873a5935d910efc6f6005c104b35c7b3a002dfcb5643fd185d1b0056'
            '4c3822d23c0d44bd335c948805aa7443c597dbd69bd87858d3295bfecc606a91')

prepare() {
    cd "$srcdir"
    asar ef "${pkgname}-${pkgver}"/resources/obsidian.asar icon.png
}

package() {
    cd "$srcdir"

    # Install executable file
    install -Dm755 "$pkgname".sh "$pkgdir"/usr/bin/obsidian

    # Install desktop file
    install -Dm644 "$pkgname".desktop -t "$pkgdir"/usr/share/applications/
    install -Dm644 icon.png "$pkgdir"/usr/share/pixmaps/obsidian.png

    # Most of the release package is electron, but we use system's default one
    # So strip away asar packages and put them to /usr/lib/
    cd "${pkgname}-${pkgver}"/resources/
    install -dm0755 "$pkgdir"/usr/lib/obsidian
    find . -type d -exec install -d {,"$pkgdir"/usr/lib/obsidian/}{} \;
    find . -type f -exec install -D {,"$pkgdir"/usr/lib/obsidian/}{} \;
}
